package it.uniroma2.tesi.bellomaria;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Film {
	
	int idfilm = 0;
	String titolo = null;
	String genere = null;
	String anno = null;
	String durata = null;
	String ind_gradimento = null;
	String desc_breve = null;
	String link = null;
	String trama = null;
	String locandina = null;
	
	public String getLocandina() {
		return locandina;
	}
	public void setLocandina(String locandina) {
		this.locandina = locandina;
	}
	public int getIdfilm() {
		return idfilm;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	public String getTrama() {
		return trama;
	}
	public void setTrama(String trama) {
		this.trama = trama;
	}
	public void setIdfilm(int idfilm) {
		this.idfilm = idfilm;
	}
	public String getTitolo() {
		return titolo;
	}
	public void setTitolo(String titolo) {
		this.titolo = titolo;
	}
	public String getGenere() {
		return genere;
	}
	public void setGenere(String genere) {
		this.genere = genere;
	}
	public String getAnno() {
		return anno;
	}
	public void setAnno(String anno) {
		this.anno = anno;
	}
	public String getDurata() {
		return durata;
	}
	public void setDurata(String durata) {
		this.durata = durata;
	}
	public String getInd_gradimento() {
		return ind_gradimento;
	}
	public void setInd_gradimento(String ind_gradimento) {
		this.ind_gradimento = ind_gradimento;
	}
	public String getDesc_breve() {
		return desc_breve;
	}
	public void setDesc_breve(String desc_breve) {
		this.desc_breve = desc_breve;
	}

	public static int getMaxIdFilm(){
		Integer maxIdFilm = 0;

		Statement statement = null;
		ResultSet rs = null;
		try {
			// si esegue lo statement.
			statement = DBConnection.getConnection().createStatement();
			String query = new String("select max(f.idfilm) from film f");
			rs = statement.executeQuery(query);
			while (rs.next()) {
				maxIdFilm = rs.getInt(1);
			}
		} catch (SQLException e) {
			System.out.println("SQLState : " + e.getSQLState());
			System.out.println("ErrorCode : " + e.getErrorCode());
			System.out.println("Message : " + e.getMessage());
			System.out.println("----------------------------------------");
		} finally {
			// rilascio delle risorse.
			try {
				rs.close();
				statement.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return maxIdFilm;
	}

	public static int findFilm(String titolo){
		int idFilm = -1;

		Statement statement = null;
		ResultSet rs = null;
		try {
			// si esegue lo statement.
			statement = DBConnection.getConnection().createStatement();
			String query = new String("select * from film f where f.titolo='"+titolo+"'");
			rs = statement.executeQuery(query);
			while (rs.next()) {
				idFilm = rs.getInt("idfilm");
			}
			
		} catch (SQLException e) {
			System.out.println("SQLState : " + e.getSQLState());
			System.out.println("ErrorCode : " + e.getErrorCode());
			System.out.println("Message : " + e.getMessage());
			System.out.println("----------------------------------------");
		} finally {
			// rilascio delle risorse.
			try {
				rs.close();
				statement.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return idFilm;
	}
}
